package com.example.aroma;

import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.os.SystemClock;
import android.app.Activity;
import android.content.Intent;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.Toast;

public class Aroma extends Activity implements OnCompletionListener{

	int progreso = 0;
	MediaPlayer player;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.activity_aroma);
		
		setVolumeControlStream(AudioManager.STREAM_MUSIC);
		
		AssetManager manager = this.getAssets();
		 player = new MediaPlayer();
		
		try{
			
			AssetFileDescriptor descriptor = manager.openFd("Summer.mp3");
		//	player.setDataSource
			
			//(descriptor.getFileDescriptor().
				//	descriptor.getStarOffset().descriptor.getLenght());
					
			player.prepare();
			
			//Reproduccion
			player.start();
			player.setOnCompletionListener(this);
		}catch(Exception e){};

	}
	@Override
	public void onCompletion(MediaPlayer arg0) {
		// TODO Auto-generated method stub
		player.stop();
		
	}
	

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.aroma, menu);
		return true;

	}

	public boolean onOptionsItemSelected(MenuItem item) {

		
		//Salimos de la aplicacion
		if (item.getItemId() == R.id.salir) {

			finish();
			System.runFinalization();
			System.exit(0);
			Aroma.this.finish();

		}

		return (true);
	}

	public void abrirTinto(View v) {
		Intent a = new Intent("com.example.aroma.Tinto");
		startActivity(a);
	}

	public void abrirBlanco(View v) {
		Intent a = new Intent("com.example.aroma.Blanco");
		startActivity(a);
	}

	public void abrirAjustes(View v) {
		Intent a = new Intent("com.example.aroma.Ajustes");

		startActivity(a);
	}

	public void abrirNotas(View v) {
		Intent a = new Intent("com.example.aroma.Notas");
		startActivity(a);
	}

	public void abrirFavoritos(View v) {
		Intent a = new Intent("com.example.aroma.Favoritos");
		startActivity(a);
	}

	// Menu barra de progreso

	/*public void progreso(final int tiempo) {
		runOnUiThread(new Runnable() {
			public void run() {
				progreso += tiempo;
				setProgress(progreso);
			}
		});

		SystemClock.sleep(tiempo);
	}

	private Runnable barraProgreso = new Runnable() {
		public void run() {
			for (int i = 0; i < 20; i++) {
				progreso(1000);

			}

			progreso = 0;
		}
	};

*/

}
